package i_iterator.a_design_pattern;

import java.lang.reflect.Method;

/**
 * Created by wug on 2016/7/14 0014.
 */
public class MyArrayListFilterIterator<E> implements MyIterator {
    private E[] array;
    private int index=0;

    public MyArrayListFilterIterator(E[] array) {
        Method[] methods = array[0].getClass().getMethods();
        for (Method method : methods) {
            if (method.getName().equals("getPrice")) {
                this.array = array;
                break;
            }
        }
    }

    @Override
    public boolean hasNext() {
        if (null != array && array.length>0 && null != array[index]) {
            return true;
        }
        return false;
    }

    @Override
    public E next() {
        index++;
        return array[index-1];
    }
}
